package com.example.sztangli.widgedemo;

import android.content.Intent;
import android.graphics.Color;

import com.example.sztangli.widgedemo.RecycleListView.RecycleActivity;
import com.example.sztangli.widgedemo.articleShow.ArticleActivity;
import com.example.sztangli.widgedemo.base.BaseActivity;
import com.example.sztangli.widgedemo.expandabelListView.ExpandableActivity;
import com.example.sztangli.widgedemo.floatingButtom.FloatingButtonActivity;
import com.example.sztangli.widgedemo.popwindow.PoPWindowActiivty;
import com.example.sztangli.widgedemo.shoppingCart.ShoppingCartActivity;
import com.example.sztangli.widgedemo.utils.ActivityUtils;
import com.example.sztangli.widgedemo.utils.ConstanceValue;
import com.example.sztangli.widgedemo.utils.SnackbarUtil;
import com.example.sztangli.widgedemo.xunfeiVoice.XunfeiVoiceActivity;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechUtility;
import java.util.ArrayList;
import java.util.Arrays;

public class MainActivity extends BaseActivity implements MainFragment.MainListener {

    private String[] widges;
    public static final String TITLE = "title";

    @Override
    public int getLayoutResId() {
        return R.layout.activity_base;
    }

    @Override
    public void initalFragment() {
        // 将“12345678”替换成您申请的APPID，申请地址：http://open.voicecloud.cn
        SpeechUtility.createUtility(this, SpeechConstant.APPID +"=59a7aa21");
        toolbar.setNavigationIcon(null);
        widges = getResources().getStringArray(R.array.widges);
        ArrayList<String> data = new ArrayList<>(Arrays.asList(widges));
        MainFragment mainFragment = MainFragment.newInstance(data);
        ActivityUtils.addFragmentToActivity(mFragmentManager, mainFragment,
                R.id.container, MainFragment.TAG);
    }

    @Override
    public void showWidge(String type) {
        switch (type) {
            case ConstanceValue.SNACKBAR:
                SnackbarUtil.showColorbar(getRootView(), "test",
                        Color.BLACK, Color.RED, Color.YELLOW);
                break;
            case ConstanceValue.EXPANDABLELISTVIEW:
                show(ExpandableActivity.class,ConstanceValue.EXPANDABLELISTVIEW);
                break;
            case ConstanceValue.RECYCLELISTVIEW:
                show(RecycleActivity.class,ConstanceValue.RECYCLELISTVIEW);
                break;
            case ConstanceValue.FLOATINGBUTTON:
                show(FloatingButtonActivity.class,ConstanceValue.FLOATINGBUTTON);
                break;
            case ConstanceValue.CART:
                show(ShoppingCartActivity.class,ConstanceValue.CART);
                break;
            case ConstanceValue.POPWINDOW:
                show(PoPWindowActiivty.class,ConstanceValue.POPWINDOW);
                break;
            case ConstanceValue.VOICERECOGNIZE:
                show(XunfeiVoiceActivity.class,ConstanceValue.VOICERECOGNIZE);
                break;
            case ConstanceValue.ARTICLESHOW:
                show(ArticleActivity.class,ConstanceValue.ARTICLESHOW);
        }
    }

    private void show(Class<?> cls,String type){
        Intent intent=new Intent(this,cls);
        intent.putExtra(TITLE,type);
        startActivity(intent);
    }
}
